/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package moonnms.libs.config;

import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Di_Moon
 */
public class NMSConfig {
    private Properties prop = new Properties();
    private String configFile;
    
    public NMSConfig(String cfgFile) {
        configFile = cfgFile;
        try {
            prop.load(new FileInputStream(configFile));
        } catch(Exception e) {
            fillDefault();
        }
    }
    
    // Сохранение конфига
    public void store() {
        try {
            prop.store(new FileOutputStream(configFile), null);
        } catch (IOException ex) {
            Logger.getLogger(NMSConfig.class.getName()).log(Level.INFO, null, ex);
        }
    }
    
    // Установка значения параметра
    public String set(String key, String value) {
        return (String)prop.setProperty(key, value);
    }
    
    // получение значения параметра
    public String get(String key, String defaultValue) {
        return prop.getProperty(key, defaultValue);
    }
    public String get(String key) {
        return prop.getProperty(key);
    }

    protected void fillDefault() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

 
}
